package com.nine.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nine.demo.entity.UserImage;
import com.nine.demo.mapper.UserImageMapper;
import com.nine.demo.service.UserImageService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author nine
 * @description 针对表【t_user_image】的数据库操作Service实现
 * @createDate 2024-08-06 22:18:39
 */
@Service
public class UserImageServiceImpl extends ServiceImpl<UserImageMapper, UserImage> implements UserImageService {

	@Override
	public boolean saveorUpdateImage(Integer uid, String bucketName, String originalFilename) {

		LambdaQueryWrapper<UserImage> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(UserImage::getUid, uid);
		// 查询数据，没有则新增，有则修改
		UserImage userImage = this.getOne(wrapper);
		if (userImage == null) {
			userImage = new UserImage();
			userImage.setUid(uid);
			userImage.setBucket(bucketName);
			userImage.setObject(originalFilename);
			userImage.setCreateTime(new Date());
			return this.save(userImage);
		}
		else {
			userImage.setUpdateTime(new Date());
			return this.update(userImage, wrapper);
		}
	}
}




